package com.boot.service;

import com.boot.proto.HelloProto;
import com.boot.proto.HelloServiceGrpc;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * 注解作用：封装如下代码
 *         ServerBuilder<?> serverBuilder = ServerBuilder.forPort(9000);
 *         serverBuilder.addService(new HelloServiceImpl());
 *         Server build = serverBuilder.build();
 *         build.start();
 *         build.awaitTermination();
 */
@GrpcService
public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {

    @Override
    public void hello(HelloProto.HelloRequest request, StreamObserver<HelloProto.HelloResponse> responseObserver) {
        String name = request.getName();
        HelloProto.HelloResponse.Builder builder = HelloProto.HelloResponse.newBuilder();
        HelloProto.HelloResponse helloResponse = builder.setResult(name + " 的响应数据 ~").build();
        responseObserver.onNext(helloResponse);
        responseObserver.onCompleted();
    }
}
